import {Module} from '@nestjs/common';
import {AppController} from './app.controller';
import {AppService} from './app.service';
import {CatsModule} from './cats/cats.module';
import {UserModule} from './user/user.module';
import {ConfigModule, ConfigService} from "@nestjs/config";
import {UserService} from "./user/user.service";
import {createConnectionPool} from "./database/mysql.connection";
import {DatabaseModule} from "./database/database.module";
import {AuthModule} from './auth/auth.module';

@Module({
    imports: [
        CatsModule,
        UserModule,
        ConfigModule.forRoot({
            isGlobal: true,
            envFilePath: '.env'
        }),
        DatabaseModule,
        AuthModule],
    controllers: [AppController],
    providers: [AppService, UserService, {
        provide: "MYSQL_CONNECTION_POOL",
        useFactory: (configService: ConfigService) => {
            return createConnectionPool(configService);
        },
        inject: [ConfigService],
    },
    ],
    exports: ['MYSQL_CONNECTION_POOL'],
})
export class AppModule {
}
